
#ifndef __TYPEDEF_H__
#define __TYPEDEF_H__

#include <stdio.h>

// 定义风格1
typedef char chr8_t;
typedef short sht16_t;
typedef int int32_t;
typedef long lng32_t;

typedef unsigned char uchr8_t;
typedef unsigned short usht16_t;
typedef unsigned int uint32_t;
typedef unsigned long ulng32_t;

// 定义风格2
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;

typedef signed char int8_t;
typedef signed short int16_t;

typedef char U8;
typedef signed char S8;
typedef unsigned short int U16;
typedef signed short int S16;

typedef unsigned int U32;
typedef signed int S32;
typedef unsigned long long U64;

typedef float F32;
typedef double F64;
typedef U8 u8_t;

typedef U16 u16_t;

/*  bool type definitions       */
typedef enum {
    USRTRUE = 1,
    USRFALSE = 0,
} usrbool;

#define sizeofstr(x)   (sizeof(x) - 1)
#define IS_DIGIT(x)    ((x) >= '0' && (x) <= '9')
#define IS_HEX(x)      (('A' <= (x) && (x) <= 'F') || ('a' <= (x) && (x) <= 'f') || IS_DIGIT(x))
#define IS_DOMAIN(x)   (('A' <= (x) && (x) <= 'Z') || ('a' <= (x) && (x) <= 'z') || IS_DIGIT(x) || ((x) == '-') || ((x) == '.'))
#define IS_FLOAT(x)    (((x) == '-') || ((x) == '.') || IS_DIGIT(x))
#define STR_EMPTY(str) (str[0] == '\0')
#define ARRAY_SIZE(x)  (sizeof(x) / sizeof((x)[0]))

#if !defined(MIN)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif

#if !defined(MAX)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif

// 十六进制转十进制
#define BCD2BIN(val) ((((0xFF & (val)) >> 4) * 10) + ((0xFF & (val)) & 0x0F))
// 十进制转十六进制
#define BIN2BCD(val) ((((0xFF & (val)) / 10) << 4) | ((0xFF & (val)) % 10))

#endif /* __TYPEDEF_H__ */